<?php
/**
 * Created by dailinlin.
 * Date: 2017/10/10 11:41
 * for:
 */

namespace app\admin\model;


use think\Db;
use think\helper\Str;
use think\Model;

class Admin extends Model
{
    protected $pk = 'id';


    //时间自动写入
    protected $autoWriteTimestamp = true;


  
    /**
     * 添加管理员
     * @param $data
     * @return bool|mixed
     */
    public function insertAdmin($data){
        $auth = false;
        $data['inpassword'] = $data['password'];

        $data['token'] = Str::random(10);
        $data['password'] = md5($data['password'].$data['token']);
        $result = $this->except('repassword,role,inpassword')->save($data);
        
        return ($result);
    }

    /**
     *  更新管理员
     * @param $data
     * @return mixed
     */
    public function updateAdmin($data){

        //密码没有改变操作
        if(strlen($data['password'])==32){
            $scene = 'Admin.noChange';
            unset($data['password']);
        }else{
            $scene = 'Admin.update';
            $data['inpassword'] = $data['password'];
            $data['password'] = md5($data['password'].$data['token']);
        }

        $result = $this->isUpdate(true)->except('role,inpassword')->save($data);
        return  $result;
    }



}